<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="学生姓名">
              <a-input placeholder="请输入学生姓名" v-model="queryParam.stName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="性别">
              <j-dict-select-tag placeholder="请选择民族" v-model="queryParam.sex" dictCode="sex"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="学号">
              <a-input placeholder="请输入学号" v-model="queryParam.studentId"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item label="学院">
                <a-input placeholder="请输入学院" v-model="queryParam.college"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="年级">
                <j-dict-select-tag placeholder="请选择年级" v-model="queryParam.fieldTwo" dictCode="grade"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="专业">
                <j-dict-select-tag placeholder="请选择专业" v-model="queryParam.profession" dictCode="st_profession,profession,id"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="班级">
                <j-dict-select-tag placeholder="请选择班级" v-model="queryParam.stClass" dictCode="st_class,classes,id"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="宿舍">
                <a-input placeholder="请输入宿舍" v-model="queryParam.dormRoom"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="政治面貌">
                <j-dict-select-tag placeholder="请选择政治面貌" v-model="queryParam.face" dictCode="face"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="家庭困难级别">
                <j-dict-select-tag placeholder="请选择家庭困难级别" v-model="queryParam.difficult" dictCode="difficult"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="单亲孤儿">
                <j-dict-select-tag placeholder="请选择单亲孤儿" v-model="queryParam.single" dictCode="single"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="心理情况">
                <j-dict-select-tag placeholder="请选择心理情况" v-model="queryParam.psychological" dictCode="psychological"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="处分">
                <j-dict-select-tag placeholder="请选择处分" v-model="queryParam.punish" dictCode="punish"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="学业预警">
                <j-dict-select-tag placeholder="请选择学业预警" v-model="queryParam.academicWarning" dictCode="whether"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="延迟毕业">
                <j-dict-select-tag placeholder="请选择延迟毕业" v-model="queryParam.delayedGraduation" dictCode="whether"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="毕业就业率">
                <j-dict-select-tag placeholder="请选择毕业就业率" v-model="queryParam.graduation" dictCode="graduation"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="民族">
                <j-dict-select-tag placeholder="请选择民族" v-model="queryParam.nationality" dictCode="nation"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="状态">
                <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="st_status"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
   <!-- <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" v-has="'stStudent:add'" >新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('学生信息')"  v-has="'stStudent:exportXls'" >导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel"  v-has="'stStudent:importExcel'" >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"  v-has="'stStudent:deleteBatch'" />删除</a-menu-item>
          <a-menu-item key="1" @click="updateStatusForBack"><a-icon type="edit"  v-has="'stStudent:updateStatus'" />批量确认归校</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>-->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{fixed:true,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="图片不存在" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)"  v-has="'stStudent:edit'" >编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item  v-has="'stStudent:edit'">
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <stStudent-modal ref="modalForm" @ok="modalFormOk"></stStudent-modal>
    <updateStatusForBack ref="updateStatusForBack" @ok="modalFormOk"></updateStatusForBack>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import StStudentModal from './modules/StStudentModal'
  import updateStatusForBack from './modules/updateStatusForBack'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import {initDictOptions, filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import JTreeSelect from '@/components/jeecg/JTreeSelect'

  export default {
    name: "StStudentList",
    mixins:[JeecgListMixin],
    components: {
      JDictSelectTag,
      StStudentModal,updateStatusForBack,JTreeSelect
    },
    data () {
      return {
        description: '学生信息管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'照片',
            align:"center",
            dataIndex: 'stPhoto'
          },
          {
            title:'学生姓名',
            align:"center",
            dataIndex: 'stName'
          },
          {
            title:'性别',
            align:"center",
            dataIndex: 'sex',
            customRender:(text)=>{
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['sex'], text+"")
              }
            }
          },
          {
            title:'学号',
            align:"center",
            dataIndex: 'studentId'
          },
          {
            title:'联系方式',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'学院',
            align:"center",
            dataIndex: 'college',
            customRender:(text)=>{
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['college'], text+"")
              }
            }
          },
          {
            title:'年级',
            align:"center",
            dataIndex: 'fieldTwo',
            customRender:(text)=>{
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['fieldTwo'], text+"")
              }
            }
          },
          {
            title:'专业',
            align:"center",
            dataIndex: 'profession',
            customRender:(text)=>{
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['profession'], text+"")
              }
            }
          },
          {
            title:'班级',
            align:"center",
            dataIndex: 'stClass',
            customRender:(text)=>{
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['stClass'], text+"")
              }
            }
          },
          {
            title:'宿舍',
            align:"center",
            dataIndex: 'dormRoom'
          },
          {
            title:'政治面貌',
            align:"center",
            dataIndex: 'face',
            customRender:(text)=>{
              console.log(text)
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['face'], text+"")
              }
            }
          },
          {
            title:'家庭困难级别',
            align:"center",
            dataIndex: 'difficult',
            customRender:(text)=>{
              console.log(text)
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['difficult'], text+"")
              }
            }
          },
          {
            title:'单亲孤儿',
            align:"center",
            dataIndex: 'single',
            customRender:(text)=>{
              console.log(text)
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['single'], text+"")
              }
            }
          },
          {
            title:'心理情况',
            align:"center",
            dataIndex: 'psychological',
            customRender:(text)=>{
              console.log(text)
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['psychological'], text+"")
              }
            }
          },
          {
            title:'处分',
            align:"center",
            dataIndex: 'punish',
            customRender:(text)=>{
              console.log(text)
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['punish'], text+"")
              }
            }
          },
          {
            title:'学业预警',
            align:"center",
            dataIndex: 'academicWarning',
            customRender:(text)=>{
              console.log(text)
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['academicWarning'], text+"")
              }
            }
          },
          {
            title:'延迟毕业',
            align:"center",
            dataIndex: 'delayedGraduation',
            customRender:(text)=>{
              console.log(text)
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['delayedGraduation'], text+"")
              }
            }
          },
          {
            title:'毕业就业率',
            align:"center",
            dataIndex: 'graduation',
            customRender:(text)=>{
              console.log(text)
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['graduation'], text+"")
              }
            }
          },
          {
            title:'民族',
            align:"center",
            dataIndex: 'nationality',
            customRender:(text)=>{
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['nationality'], text+"")
              }
            }
          },
          {
            title:'省',
            align:"center",
            dataIndex: 'province_dictText'
          },
          {
            title:'市',
            align:"center",
            dataIndex: 'city_dictText'
          },
          {
            title:'区/县',
            align:"center",
            dataIndex: 'area_dictText',
          },
          {
            title:'家庭地址',
            align:"center",
            dataIndex: 'familyAddress'
          },
          {
            title:'家长1',
            align:"center",
            dataIndex: 'parentOne'
          },
          {
            title:'家长2',
            align:"center",
            dataIndex: 'parentTwo'
          },
          {
            title:'家长电话1',
            align:"center",
            dataIndex: 'phoneOne'
          },
          {
            title:'家长电话2',
            align:"center",
            dataIndex: 'phoneTwo'
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status',
            customRender:(text)=>{
              if(!text){
                return ''
              }else{
                return filterMultiDictText(this.dictOptions['status'], text+"")
              }
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/st/mobile/getSchoolDifficult",
          delete: "/st/stStudent/delete",
          deleteBatch: "/st/stStudent/deleteBatch",
          exportXlsUrl: "/st/stStudent/exportXls",
          importExcelUrl: "st/stStudent/importExcel",
        },
        dictOptions:{
         college:[],
         fieldTwo:[],
         profession:[],
         stClass:[],
         face:[],
         difficult:[],
         single:[],
         psychological:[],
         punish:[],
         academicWarning:[],
          delayedGraduation:[],
          repeatStudent:[],
          keepStudent:[],
         graduation:[],
         nationality:[],
          sex:[],
         status:[],
        },
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      updateStatusForBack(){
        console.log(this.selectedRowKeys)
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！')
        } else {
          var ids = ''
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ','
          }
          this.$refs.updateStatusForBack.updateStatus(ids);
          this.$refs.updateStatusForBack.title = "批量修改学生状态";
        }
      },
      initDictConfig(){
        initDictOptions('sys_depart,depart_name,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'college', res.result)
          }
        })
        initDictOptions('grade').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'fieldTwo', res.result)
          }
        })
        initDictOptions('st_profession,profession,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'profession', res.result)
          }
        })
        initDictOptions('st_class,classes,id').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'stClass', res.result)
          }
        })
        initDictOptions('face').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'face', res.result)
          }
        })
        initDictOptions('difficult').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'difficult', res.result)
          }
        })
        initDictOptions('single').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'single', res.result)
          }
        })
        initDictOptions('psychological').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'psychological', res.result)
          }
        })
        initDictOptions('punish').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'punish', res.result)
          }
        })
        initDictOptions('whether').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'academicWarning', res.result)
          }
        })
        initDictOptions('whether').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'delayedGraduation', res.result)
          }
        })
        initDictOptions('whether').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'repeatStudent', res.result)
          }
        })
        initDictOptions('whether').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'keepStudent', res.result)
          }
        })
        initDictOptions('graduation').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'graduation', res.result)
          }
        })
        initDictOptions('nation').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'nationality', res.result)
          }
        })
        initDictOptions('sex').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'sex', res.result)
          }
        })
        initDictOptions('st_status').then((res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'status', res.result)
          }
        })
      }
       
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>